package com.bkgy.modular.configureRules.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.bkgy.modular.configureRules.dto.LTRigidSeedGrading2130Dto;
import com.bkgy.modular.configureRules.entity.LTRigidSeedGrading2130;
import com.bkgy.modular.configureRules.mapper.LTRigidSeedGrading2130Mapper;
import com.bkgy.modular.configureRules.service.LTRigidSeedGrading2130Service;
import com.bkgy.sys.common.entity.ResultData;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author
 * @version 1.0
 * @ClassName LTRigidSeedGrading2130ServiceImpl
 * @date 2023/4/19 10:39
 */
@Service
public class LTRigidSeedGrading2130ServiceImpl extends ServiceImpl<LTRigidSeedGrading2130Mapper, LTRigidSeedGrading2130> implements LTRigidSeedGrading2130Service {
    @Resource
    private LTRigidSeedGrading2130Mapper ltRigidSeedGrading2130Mapper;

    @Override
    public ResultData queryltRigidSeedGrading2130() {
        List<LTRigidSeedGrading2130> list = ltRigidSeedGrading2130Mapper.selectList(null);
        return ResultData.ResultDataFaultSelf("操作成功",list);
    }

    @Override
    public ResultData updateLtRigidSeedGrading2130(LTRigidSeedGrading2130Dto dto) {
        String steel_grade = dto.getSteel_grade();
        if (StringUtils.isEmpty(steel_grade)) {
            return ResultData.ResultDataFaultSelf("参数有误,请检查参数",-1);
        }
        String inner_grade = dto.getInner_grade();
        Double yield = dto.getYield();
        Double group_id = dto.getGroup_id();
        String purpose_group = dto.getPurpose_group();
        String remarks = dto.getRemarks();

        LambdaQueryWrapper<LTRigidSeedGrading2130> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(LTRigidSeedGrading2130::getSteel_grade,steel_grade);

        LTRigidSeedGrading2130 ltRigidSeedGrading2130 = ltRigidSeedGrading2130Mapper.selectOne(queryWrapper);
        ltRigidSeedGrading2130.setInner_grade(inner_grade);
        ltRigidSeedGrading2130.setYield(yield);
        ltRigidSeedGrading2130.setGroup_id(group_id);
        ltRigidSeedGrading2130.setPurpose_group(purpose_group);
        ltRigidSeedGrading2130.setRemarks(remarks);

        int flag = ltRigidSeedGrading2130Mapper.update(ltRigidSeedGrading2130, queryWrapper);
        if (flag == 1) {
            return ResultData.ResultDataFaultSelf("操作成功",1);
        }
        return  ResultData.ResultDataFaultSelf("操作失败",-1);
    }
}
